package com.qf.homework.controller;

import com.qf.homework.controller.entity.Category;
import com.qf.homework.service.CategoryService;
import com.qf.homework.service.impl.CategoryServiceImpl;
import com.qf.homework.utils.ResponseEntity;
import com.qf.homework.utils.ResponseUtils;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


@WebServlet("/Category/list")
public class CategoryListController extends HttpServlet {
    private CategoryService categoryService=new CategoryServiceImpl();


    /**
     * 分页查找分类
     * @author tomyeung-李尐达
     * @param currentPage 当前页
     * @since 2021年1月12日19:12:33
     */
    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=utf-8");
        System.out.println(1);
        //获取当前页
        String currentPageStr = req.getParameter("currentPage");
        int currentPage=0;
        if (currentPageStr!=null){currentPage=Integer.parseInt(currentPageStr);}
        //设置默认页面大小
        int size=3;
        ResponseEntity<List<Category>> responseEntity=new ResponseEntity<>();
        //分页查询
        try {
            List<Category> list = categoryService.getCategoryList(currentPage, size);
            ResponseUtils.success(resp,responseEntity,list,null);
        }catch (Exception e)
        {
            ResponseUtils.fail(resp,responseEntity);
        }

    }
}
